package cn.lingyangwl.agile.food.core.controller.admin;

import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.food.core.service.GoodsSkuService;
import cn.lingyangwl.agile.food.model.rqrs.sku.SkuPageReq;
import cn.lingyangwl.agile.food.model.rqrs.sku.SkuReq;
import cn.lingyangwl.agile.food.model.rqrs.sku.SkuResp;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 商品sku
 * 
 * @author shenguangyang
 */
@Api(tags = "商品sku")
@RestController
@RequestMapping("/sku")
public class GoodsSkuController {
    @Resource
    private GoodsSkuService skuService;

    @ApiOperation(value = "分页商品sku")
    @GetMapping("/page")
    @RamResource(action = "shopGoods:sku:query", name = "查询商品sku", type = ActionType.READ)
    public Resp<IPage<SkuResp>> pageSku(@Validated SkuPageReq req) {
        return Resp.ok(skuService.pageSku(req));
    }

    @ApiOperation(value = "通过id查找商品sku")
    @GetMapping("/get")
    @RamResource(action = "shopGoods:sku:query", name = "查询商品sku", type = ActionType.READ)
    public Resp<SkuResp> getSku(@RequestParam(value = "id") Long id) {
        return Resp.ok(skuService.getSku(id));
    }
  
    @ApiOperation(value = "保存商品sku")
    @PostMapping("/save")
    @RamResource(action = "shopGoods:sku:save", name = "保存商品sku", type = ActionType.WRITE)
    public Resp<?> saveSku(@Validated @RequestBody SkuReq req) {
        return Resp.ok(skuService.saveSku(req));
    }
  
    @ApiOperation(value = "更新商品sku")
    @PostMapping("/update")
    @RamResource(action = "shopGoods:sku:update", name = "更新商品sku", type = ActionType.WRITE)
    public Resp<?> updateSku(@Validated @RequestBody SkuReq req) {
        return Resp.ok(skuService.updateSku(req));
    }
  
    @ApiOperation(value = "批量删除商品sku")
    @DeleteMapping("/batchDelete")
    @RamResource(action = "shopGoods:sku:delete", name = "删除商品sku", type = ActionType.WRITE)
    public Resp<?> batchDeleteSku(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(skuService.batchDeleteSku(ids));
    }
  
    @ApiOperation(value = "删除商品sku")
    @DeleteMapping("/delete")
    @RamResource(action = "shopGoods:sku:delete", name = "删除商品sku", type = ActionType.WRITE)
    public Resp<?> deleteSku(@RequestParam(value = "id") Long id) {
        return Resp.ok(skuService.deleteSku(id));
    }
}
